//
// Created by 束庆乐 on 2025/1/4.
//
#include "iostream"
using namespace std;

template<typename T>
void mySwap(T& a,T& b){
    T temp = a;
    a = b;
    b = temp;
}
//也可以替换为typename
template<class T>
//利用选择排序，对数组进行大小排序
void mySort(T arr[],int len){
    for (int i = 0; i < len; i++) {
        int max=i;
        for (int j = i+1; j < len; j++) {
            if(arr[max] < arr[j]){
                max = j;
            }
        }
        if(max != i){
            mySwap(arr[max],arr[i]);
        }
    }
}

template<typename T>
void printArr(T arr[],int len){
    for (int i = 0; i < len; i++) {
        cout << arr[i] << " " ;
    }
    cout << endl;
}

void test1(){
    char charArr[] = "abcdefg";
    int num = sizeof(charArr)/sizeof(char);
    mySort(charArr,num);
    printArr(charArr,num);
}

void test2(){
    int intArr[] = {1,3,4,2,5};
    int num = sizeof(intArr)/ sizeof(int);
    mySort(intArr,num);
    printArr(intArr,num);
}

int main098(){
    test1();
    test2();

    return 0;
}